package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsStorage;
import com.qf.pojo.DtsUser;
import com.qf.pojo.DtsUserAccount;
import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.aspectj.lang.annotation.Around;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author YDW
 * projectName:shop-manage
 * time:2022/5/23 10:22
 * description:
 */
@RestController
@RequestMapping("/admin/user")
public class AdminUserContorller {

    @Autowired
    DtsUserService dtsUserService;

    @RequiresPermissions("admin:user:list")
    @RequiresPermissionsDesc(menu = { "用户管理", "会员管理" }, button = "查询")
    @GetMapping("/list")
    public Object list(
            @RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
            @RequestParam(name = "limit",required = false,defaultValue = "10") Integer limit,
            String sort,String order, String username,String mobile
    ){
        IPage<DtsUser> ipage=dtsUserService.queryPage(page,limit,sort,order,username,mobile);
        Map<String,Object> data=new HashMap<>();
        data.put("total",ipage.getTotal());
        data.put("items",ipage.getRecords());
        return ResponseUtil.ok(data);
    }
    @RequiresPermissions("admin:user:approveAgency")
    @RequiresPermissionsDesc(menu = { "用户管理", "会员管理" }, button = "审批")
    @PostMapping("/approveAgency")
    public Object approveAgency(@RequestBody Map<String,Object> map){
        Integer userId = (Integer) map.get("userId");
        String settlementRate = (String) map.get("settlementRate");
        try {
            dtsUserService.updateapproveAgency(userId,new Integer(settlementRate));
        } catch (Exception e) {
            return ResponseUtil.fail(-1,"审批失败，请联系管理员");
        }
        return ResponseUtil.ok();

    }

    @RequiresPermissions("admin:user:detailApprove")
    @RequiresPermissionsDesc(menu = { "用户管理", "会员管理" }, button = "推广代理")
    @GetMapping("/detailApprove")
    public Object detailApprove(Integer id){
        DtsUserAccount account=dtsUserService.findUserAccountById(id);
        return ResponseUtil.ok(account);

    }


}
